]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Add magic 'restart' command to run dialog which re-executes
authorColin Walters <walters@src.gnome.org>
Thu, 18 Dec 2008 20:57:37 +0000 (20:57 +0000)
committerColin Walters <walters@src.gnome.org>
Thu, 18 Dec 2008 20:57:37 +0000 (20:57 +0000)
This is immensely convenient for debugging.  The shell global reexec_self
only works on Linux, sue me.

http://bugzilla.gnome.org/show_bug.cgi?id=565037

svn path=/trunk/; revision=130

js/ui/runDialog.js
src/shell-global.c
src/shell-global.h

index fdfd36a8c42d1ce2ec756dcfbcc63d9c4cde6677..fd634471179d5e2cc49a9bf025bb2f733c9e37f3 100644 (file)
@@ -78,7 +78,10 @@ RunDialog.prototype = {
     },
 
     _run : function(command) {
-        if (command) {
+        if (command == 'restart') {
+            let global = Shell.Global.get();
+            global.reexec_self();
+        } else if (command) {
             var p = new Shell.Process({'args' : [command]});
             try {
                 p.run();
index 55b8378599130659afdcbb1c413b3f9f1261ff08..5d57437f001a29f4052254667f06c98e4f823805 100644 (file)
@@ -5,6 +5,9 @@
 
 #include "display.h"
 #include <clutter/x11/clutter-x11.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
 
 struct _ShellGlobal {
   GObject parent;
@@ -335,3 +338,38 @@ shell_global_ungrab_keyboard (ShellGlobal *global)
 
   global->keyboard_grabbed = FALSE;
 }
+
+/**
+ * shell_global_reexec_self:
+ * @global: A #ShellGlobal
+ * 
+ * Restart the current process.  Only intended for development purposes. 
+ */
+void 
+shell_global_reexec_self (ShellGlobal *global)
+{
+  GPtrArray *arr;
+  gsize len;
+  char *buf;
+  char *buf_p;
+  char *buf_end;
+  GError *error = NULL;
+  
+  /* Linux specific (I think, anyways). */
+  if (!g_file_get_contents ("/proc/self/cmdline", &buf, &len, &error))
+    {
+      g_warning ("failed to get /proc/self/cmdline: %s", error->message);
+      return;
+    }
+      
+  buf_end = buf+len;
+  arr = g_ptr_array_new ();
+  /* The cmdline file is NUL-separated */
+  for (buf_p = buf; buf_p < buf_end; buf_p = buf_p + strlen (buf_p) + 1)
+    g_ptr_array_add (arr, buf_p);
+  
+  g_ptr_array_add (arr, NULL); 
+  execvp (arr->pdata[0], (char**)arr->pdata);
+  g_warning ("failed to reexec: %s", g_strerror (errno));
+  g_ptr_array_free (arr, TRUE);
+}
\ No newline at end of file
index 1970b0ac4967ca869181e30e3cc80104494a8d6f..8888cebec64227db44e6e6ee5fcae00d63bbfd4f 100644 (file)
@@ -52,6 +52,8 @@ MetaScreen * shell_global_get_screen (ShellGlobal *global);
 gboolean shell_global_grab_keyboard   (ShellGlobal *global);
 void     shell_global_ungrab_keyboard (ShellGlobal *global);
 
+void shell_global_reexec_self (ShellGlobal *global);
+
 G_END_DECLS
 
 #endif /* __SHELL_GLOBAL_H__ */